package snippets;

import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;

public class ResizeBmp {
	public static void scale(String srcFile, int destWidth, int destHeight,
			String destFile) throws IOException {
		BufferedImage src = ImageIO.read(new File(srcFile));
		BufferedImage dest = new BufferedImage(destWidth, destHeight,
				BufferedImage.TYPE_INT_RGB);
		Graphics2D g = dest.createGraphics();
		AffineTransform at = AffineTransform.getScaleInstance(
				(double) destWidth / src.getWidth(), (double) destHeight
						/ src.getHeight());
		g.drawRenderedImage(src, at);
		ImageIO.write(dest, "BMP", new File(destFile));
	}

	public static void main(String[] args) {
		if (args.length == 4) {
			try {

				scale(args[0], Integer.parseInt(args[1]), Integer
						.parseInt(args[2]), args[3]);
			} catch (Exception e) {
				System.out.println(e);
			}
		}
	}
}